#include <bits/stdc++.h>
#define fori(i,a,b) for(int i = a;i <= b;i ++)
#define fore(i,a,b) for(int i = a;i >= b;i --)
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define bit(n,i) ((n >> i) & 1)
using namespace std;
typedef long long ll;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int l,int r)
{
return l + rng() % (r - l + 1);
}
int const N = 2e5 + 10;
int a[N],dp[N];
void speed()
{
ios_base::sync_with_stdio(NULL);
cin.tie(NULL);
cout.tie(NULL);
}
int t,n;
void solve()
{
cin >> n;
fori(i,1,n)
{
cin >> a[i];
dp[i] = 0;
}
ll res(0);
fori(i,1,n)
{
ll c = a[i] - dp[i] - 1;
res += max(0ll,c);
for(int j = i + 2;j <= min(n,a[i] + i);j ++)
dp[j] += 1;
if(i < n and c < 0) dp[i + 1] -= c;
}
cout << res;
}
int main()
{
if(fopen("task.inp","r"))
{
freopen("task.inp","r",stdin);
freopen("task.out","w",stdout);
}
cin >> t;
while(t--)
{
solve();
cout << "\n";
}
return 0;
}
Health of a person | Divisibility |
A. Movement | Numbers in a matrix |
Sequences | Split houses |
Divisible | Three primes |
Coprimes | Cost of balloons |
One String No Trouble | Help Jarvis! |
Lift queries | Goki and his breakup |
Ali and Helping innocent people | Book of Potion making |
Duration | Birthday Party |
e-maze-in | Bricks Game |
Char Sum | Two Strings |
Anagrams | Prime Number |
Lexical Sorting Reloaded | 1514A - Perfectly Imperfect Array |
580A- Kefa and First Steps | 1472B- Fair Division |
996A - Hit the Lottery | MSNSADM1 Football |